<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="./node_modules/vue/dist/vue.js"></script>
  </head>

  <body>
    <div id="app">
      {{msg}}

      <Foo></Foo>
      <Bar></Bar>
    </div>
    <script>
      // mixin

      // v-if v-for v-show 指令
      const mousemoveMixin = {
        data() {
          return {
            x: 0,
            y: 0,
          };
        },
        mounted() {
          window.addEventListener("mousemove", this.handleMousemove);
        },
        methods: {
          handleMousemove(e) {
            this.x = e.pageX;
            this.y = e.pageY;
          },
        },
      };

      const Bar = {
        template: `<div>bar {{x}} -- {{y}}</div>`,
        mixins: [mousemoveMixin],
      };

      const Foo = {
        // mixin 的问题
        // 1. x y ?  来源不清晰的问题
        // 2. x y -> x y ? 命名冲突的问题
        // vue3 -> composition api
        mixins: [mousemoveMixin, fooMixin, barMixin, otherMixin],
        template: `<div>foo
          
          {{x}} -- {{y}}
          
          </div>`,
      };

      const app = new Vue({
        el: "#app",
        components: {
          Foo,
          Bar,
        },
        data: {
          msg: "hello ",
        },
      });
    </script>
  </body>
</html>
